package org.ww.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ww.commonutils.R;
import org.ww.edu.bean.Course;
import org.ww.edu.bean.Teacher;
import org.ww.edu.service.CourseService;
import org.ww.edu.service.TeacherService;

import javax.annotation.security.PermitAll;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/edu/teacherfront")
//@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;

    /**
     * 分页查询讲师信息
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/pageTeacherFront/{page}/{limit}")
    public R pageTeacherFront(@PathVariable Long page,@PathVariable Long limit){
        Page<Teacher> pageTeacher=new Page<>(page,limit);
        Map<String,Object> map=teacherService.pageTeacherFront(pageTeacher);
        return R.ok().data(map);
    }

    /**
     * 根据id查询讲师
     * @param id
     * @return
     */
    @GetMapping("/getTeacherCourseInfo/{id}")
    public R getTeacherCourseInfo(@PathVariable String id){
        //1 根据讲师id查询讲师详情
        Teacher teacher = teacherService.getById(id);

        //2 根据讲师id查询所讲课程
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<Course> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }


}
